using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.Interfaces;
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Application.Services
{
    /// <summary>
    /// 日志服务。
    /// 提供不同类型日志的写入功能，包括操作日志、异常日志和访问日志。
    /// </summary>
    [JGSY.CMS.LowCode.Platform.Infrastructure.Services.LogOperation]
    public class LogService : ILogService
    {
        /// <summary>
        /// 审计日志应用服务接口
        /// </summary>
        private readonly IAuditLogAppService _auditLogAppService;
        
        /// <summary>
        /// 构造函数，注入审计日志应用服务
        /// </summary>
        /// <param name="auditLogAppService">审计日志应用服务接口</param>
        public LogService(IAuditLogAppService auditLogAppService)
        {
            _auditLogAppService = auditLogAppService;
        }
        
        /// <summary>
        /// 写入操作日志
        /// </summary>
        /// <param name="dto">审计日志数据传输对象</param>
        /// <returns>写入任务</returns>
        public async Task WriteOperationAsync(AuditLogDto dto)
        {
            dto.Type = "Operation";
            await _auditLogAppService.AddAsync(dto);
        }
        
        /// <summary>
        /// 写入异常日志
        /// </summary>
        /// <param name="dto">审计日志数据传输对象</param>
        /// <returns>写入任务</returns>
        public async Task WriteExceptionAsync(AuditLogDto dto)
        {
            dto.Type = "Exception";
            await _auditLogAppService.AddAsync(dto);
        }
        
        /// <summary>
        /// 写入访问日志
        /// </summary>
        /// <param name="dto">审计日志数据传输对象</param>
        /// <returns>写入任务</returns>
        public async Task WriteAccessAsync(AuditLogDto dto)
        {
            dto.Type = "Access";
            await _auditLogAppService.AddAsync(dto);
        }
    }
}
